package com.example.back.utils;

import cn.hutool.core.util.StrUtil;
import org.springframework.util.DigestUtils;

import java.util.Random;
import java.util.UUID;

/**
 * @author Jm
 * @date 2024/7/13
 */
public class StringUtil
{
    /**
     * 生成随机字符串
     */
    public static String generateUUID()
    {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    /**
     * MD5加密
     */
    public static String md5(String key)
    {
        if(StrUtil.isBlank(key))
        {
            return null;
        }
        return DigestUtils.md5DigestAsHex(key.getBytes());
    }

    public static Integer changeString(String string)
    {
        if(string != null && !StrUtil.isBlank(string))
        {
            return Integer.valueOf(string);
        } else
        {
            return null;
        }
    }

    public static String getSalt()
    {
        String salt = generateUUID();
        return salt.substring(0,5);
    }


    public static void main(String[] args)
    {
        System.out.println(md5("123" + "key"));
    }
}
